package cn.xfdzx.android.apps.shop.adapter.remake;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.DissatisfiedReasonBean;
import cn.xfdzx.android.apps.shop.bean.OrderListBeen;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;

/**
 * Creator: zf.
 * Date: 2020/9/10.
 * Description:订单评价商品列表适配器.
 */
public class OrderRemakeGoodsAdapter extends BaseQuickAdapter<OrderListBeen.DataBean.CartInfoBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    public OrderRemakeGoodsAdapter(@Nullable List<OrderListBeen.DataBean.CartInfoBean> data) {
        super(R.layout.item_remakegoods, data);
    }

    @Override
    public void setData(int index, @NonNull OrderListBeen.DataBean.CartInfoBean data) {
        super.setData(index, data);
    }

    @Override
    protected void convert(final BaseViewHolder viewHolder, final OrderListBeen.DataBean.CartInfoBean date) {
        TextView tv_cai = viewHolder.getView(R.id.tv_cai);
        TextView tv_zan = viewHolder.getView(R.id.tv_zan);
        ImageView imageView = viewHolder.getView(R.id.img_goods);
        ImageGlideUtil.loadImage(mContext,imageView,date.getProductInfo().getImage());

        viewHolder.setText(R.id.tv_goods_title,date.getProductInfo().getStore_name());
        tv_cai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (date.getIs_fabulous()==2){//踩
                   return;
                }else {
                    setDrawableLeft(tv_cai,mContext.getResources().getDrawable(R.drawable.ic_caisel));
                    setDrawableLeft(tv_zan,mContext.getResources().getDrawable(R.drawable.ic_zannor));
                    date.setIs_fabulous(2);
                }
                onItemOnClickListener.onItemOnClick(viewHolder.getLayoutPosition(),date);
            }
        });

        tv_zan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (date.getIs_fabulous()==1){//赞
                    return;
                }else {
                    setDrawableLeft(tv_cai,mContext.getResources().getDrawable(R.drawable.ic_cainor));
                    setDrawableLeft(tv_zan,mContext.getResources().getDrawable(R.drawable.ic_zansel));
                    date.setIs_fabulous(1);
                }
                onItemOnClickListener.onItemOnClick(viewHolder.getLayoutPosition(),date);
            }
        });


    }

    private void setDrawableLeft(TextView tv_cai,Drawable drawable) {
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv_cai.setCompoundDrawables(drawable, null, null, null);
    }

    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<OrderListBeen.DataBean.CartInfoBean> list){
        super.replaceData(list);
    }

    public void setItemZanCaiClickListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemOnClick(int position, OrderListBeen.DataBean.CartInfoBean date);
    }

}
